<template>
  <!-- 新增活动 -->
  <div class="content">
    <h2 class="u-title-h2">新增活动</h2>
    <h3 class="u-title-h3">活动设置</h3>
    <hr />
    <div class="u-form-box">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="140px"
        class="demo-ruleForm"
      >
        <el-form-item label="活动名称：" prop="name">
          <el-input
            v-model="ruleForm.name"
            placeholder="请输入活动名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="活动类型：" prop="type">
          <el-select v-model="ruleForm.type" placeholder="请选择优惠券类型：">
            <el-option
              v-for="(item, index) in selectArr.type"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品类型：" prop="goods_type">
          <el-select
            v-model="ruleForm.goods_type"
            placeholder="请选择商品类型："
          >
            <el-option
              v-for="(item, index) in selectArr.goods_type"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="教材版本：" prop="book_type">
          <el-select
            v-model="ruleForm.book_type"
            placeholder="请选择优惠券类型："
          >
            <el-option
              v-for="(item, index) in selectArr.book_type"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属年级：" prop="grade">
          <el-select v-model="ruleForm.grade" placeholder="请选择优惠券类型：">
            <el-option
              v-for="(item, index) in selectArr.grade"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间：" prop="start_time">
          <el-date-picker
            class="u-time-box"
            v-model="ruleForm.start_time"
            :editable="false"
            :placeholder="'请选择开始时间'"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="changeListTime"
            :picker-options="pickerOptions"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间：" prop="end_time">
          <el-date-picker
            class="u-time-box"
            v-model="ruleForm.end_time"
            :editable="false"
            :placeholder="
              ruleForm.start_time
                ? '选择时间(不早于' + ruleForm.start_time + ')'
                : '请选择结束时间'
            "
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            :disabled="!ruleForm.start_time"
            :picker-options="pickerOptions"
            @change="setEndTime"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="赠送金币：" prop="coins">
          <el-input
            v-model="ruleForm.coins"
            placeholder="请输入赠送金币"
          ></el-input>
        </el-form-item>
        <el-form-item label="购买基数：" prop="buy_radix">
          <el-input
            v-model="ruleForm.buy_radix"
            placeholder="请输入购买基数"
          ></el-input>
        </el-form-item>

        <el-form-item
          label="活动封面"
          prop="cover_path"
          :required="true"
          :show-message="!ruleForm.cover_path"
        >
          <el-upload
            :http-request="uploadImg"
            class="avatar-uploader"
            :show-file-list="false"
            :before-upload="beforeUploadImg"
            action
          >
            <img
              v-if="ruleForm.cover_path"
              :src="ruleForm.cover_path"
              class="avatar"
            />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <p class="u-info-text">
            上传封面为.jpg.png格式，建议图片尺寸为800(宽)*378(高)，图片大小不超过5MB。
          </p>
        </el-form-item>
        <el-form-item
          label="活动海报"
          prop="cover_path"
          :required="true"
          :show-message="!ruleForm.poster_path"
        >
          <el-upload
            :http-request="uploadImg_poster_path"
            class="avatar-uploader"
            :show-file-list="false"
            :before-upload="beforeUploadImg"
            action
          >
            <img
              v-if="ruleForm.poster_path"
              :src="ruleForm.poster_path"
              class="avatar"
            />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <p class="u-info-text">
            上传海报为.jpg.png格式，建议图片尺寸为800(宽)*378(高)，图片大小不超过5MB。
          </p>
        </el-form-item>
      </el-form>
    </div>
    <h3 class="u-title-h3">商品设置</h3>
    <hr />
    <div>
      <h3 class="u-title-h3">报1门</h3>
      <el-form
        :model="formBox_1"
        label-width="140px"
        class="demo-ruleForm"
        :inline="true"
      >
        <el-form-item label="秒杀价：">
          <el-input
            v-model="formBox_1.price"
            placeholder="请输入秒杀价"
          ></el-input>
        </el-form-item>
        <el-form-item label="原价：">
          <el-input
            v-model="formBox_1.original_price"
            placeholder="请输入原价"
          ></el-input>
        </el-form-item>
      </el-form>

      <div
        class="u-list-box"
        v-for="(item, index) in formBox_1_arr"
        :key="index"
      >
        <div>
          <b class="u-list-name">名称：{{ item.goods_name }}</b> 课程名称：
          <el-tag
            class="u-mar-right-20"
            v-for="item_ in item.course"
            :key="item_.course_id"
            >{{ item_.course_Name }}</el-tag
          >
        </div>
        <div>
          <el-button
            type="danger"
            size="mini"
            :disabled="$route.query.mode != 'add'"
            @click="deleteBox('formBox_1_arr', index)"
            >删除</el-button
          >
        </div>
      </div>

      <div id="select_1">
        <el-form
          :model="formBox_1"
          label-width="140px"
          class="demo-ruleForm"
          :inline="true"
        >
          <el-form-item label="名称：">
            <el-input
              v-model="formBox_1.name"
              placeholder="请输入名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="课程名称：">
            <el-select
              v-model="formBox_1.className"
              multiple
              filterable
              remote
              reserve-keyword
              placeholder="请输入课程名称"
              :remote-method="remoteMethod"
              :loading="loading"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <!-- <el-input v-model="formBox_1.className" placeholder="请输入课程名称"></el-input> -->
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              :disabled="$route.query.mode != 'add'"
              size="small"
              @click="addCourse('formBox_1', 1)"
              >确定</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>

    <hr />
    <div>
      <h3 class="u-title-h3">2门联报</h3>
      <el-form
        :model="formBox_2"
        label-width="140px"
        class="demo-ruleForm"
        :inline="true"
      >
        <el-form-item label="秒杀价：">
          <el-input
            v-model="formBox_2.price"
            placeholder="请输入秒杀价"
          ></el-input>
        </el-form-item>
        <el-form-item label="原价：">
          <el-input
            v-model="formBox_2.original_price"
            placeholder="请输入原价"
          ></el-input>
        </el-form-item>
      </el-form>

      <div
        class="u-list-box"
        v-for="(item, index) in formBox_2_arr"
        :key="index"
      >
        <div>
          <b class="u-list-name">名称：{{ item.goods_name }}</b> 课程名称：
          <el-tag
            class="u-mar-right-20"
            v-for="item_ in item.course"
            :key="item_.course_id"
            >{{ item_.course_Name }}</el-tag
          >
        </div>
        <div>
          <el-button
            type="danger"
            size="mini"
            :disabled="$route.query.mode != 'add'"
            @click="deleteBox('formBox_2_arr', index)"
            >删除</el-button
          >
        </div>
      </div>

      <div id="select_2">
        <el-form
          :model="formBox_2"
          label-width="140px"
          class="demo-ruleForm"
          :inline="true"
        >
          <el-form-item label="名称：">
            <el-input
              v-model="formBox_2.name"
              placeholder="请输入名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="课程名称：">
            <el-select
              v-model="formBox_2.className"
              multiple
              filterable
              remote
              reserve-keyword
              placeholder="请输入课程名称"
              :remote-method="remoteMethod"
              :loading="loading"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <!-- <el-input v-model="formBox_2.className" placeholder="请输入课程名称"></el-input> -->
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              :disabled="$route.query.mode != 'add'"
              size="small"
              @click="addCourse('formBox_2', 2)"
              >确定</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
    <hr />
    <div>
      <h3 class="u-title-h3">3门联报</h3>
      <el-form
        :model="formBox_3"
        label-width="140px"
        class="demo-ruleForm"
        :inline="true"
      >
        <el-form-item label="秒杀价：">
          <el-input
            v-model="formBox_3.price"
            placeholder="请输入秒杀价"
          ></el-input>
        </el-form-item>
        <el-form-item label="原价：">
          <el-input
            v-model="formBox_3.original_price"
            placeholder="请输入原价"
          ></el-input>
        </el-form-item>
      </el-form>

      <div
        class="u-list-box"
        v-for="(item, index) in formBox_3_arr"
        :key="index"
      >
        <div>
          <b class="u-list-name">名称：{{ item.goods_name }}</b> 课程名称：
          <el-tag
            class="u-mar-right-20"
            v-for="item_ in item.course"
            :key="item_.course_id"
            >{{ item_.course_Name }}</el-tag
          >
        </div>
        <div>
          <el-button
            type="danger"
            size="mini"
            :disabled="$route.query.mode != 'add'"
            @click="deleteBox('formBox_3_arr', index)"
            >删除</el-button
          >
        </div>
      </div>

      <div id="select_3">
        <el-form
          :model="ruleForm"
          label-width="140px"
          class="demo-ruleForm"
          :inline="true"
        >
          <el-form-item label="名称：">
            <el-input
              v-model="formBox_3.name"
              placeholder="请输入名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="课程名称：">
            <el-select
              v-model="formBox_3.className"
              multiple
              filterable
              remote
              reserve-keyword
              placeholder="请输入课程名称"
              :remote-method="remoteMethod"
              :loading="loading"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <!-- <el-input v-model="formBox_3.className" placeholder="请输入课程名称"></el-input> -->
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              size="small"
              :disabled="$route.query.mode != 'add'"
              @click="addCourse('formBox_3', 3)"
              >确定</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>

    <el-button
      class="u-save"
      :disabled="$route.query.mode != 'add'"
      type="primary"
      @click="submitForm('ruleForm', 0)"
      >保存</el-button
    >
  </div>
</template>
<script>
import jquery from 'jquery'
import { getCourseList } from '@/api/course.js'
import {
  queyEnumByTableName,
  tableInsert,
  ossUpload
  // tableUpdate
} from '@/api/api.js'
import { getCourseById, updateCourse } from '@/api/course.js'
import {
  addActivity,
  getActivityResource,
  getActivityDetails
} from '@/api/coupon.js'
export default {
  name: 'add-update-class',
  data () {
    var levelRule = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请选择难度'))
      } else {
        callback()
      }
    }
    return {
      loading: false,
      options: [],
      pickerOptions: {
        disabledDate (date) {
          return date.getTime() < Date.now() - 8.64e7
        }
      },
      earliestTime: '',
      isOpen: false,
      gradeCopy: null,
      gradeLabel: '全部',
      showRentPrise: false,
      percentage: 0,
      ismultiple: false,
      selectArr: {
        type: [],
        grade: [],
        discount_type: [],
        book_type: [],
        goods_type: []
      },
      texts: ['简单', '简单', '一般', '一般', '困难'],
      value2: null,
      colors: ['#99A9BF', '#F7BA2A', 'red'],
      ruleForm: {
        name: '',
        type: '',
        grade: '',
        start_time: '',
        end_time: '',
        coins: '',
        buy_radix: '',
        book_type: '',
        cover_path: '',
        poster_path: '',
        goods_type: ''
      },
      formBox_1: {
        original_price: '',
        discount_type: 1,
        price: '',
        name: '',
        className: []
      },
      formBox_1_arr: [],
      formBox_2: {
        original_price: '',
        discount_type: 2,
        price: '',
        name: '',
        className: []
      },
      formBox_2_arr: [],
      formBox_3: {
        original_price: '',
        discount_type: 3,
        price: '',
        name: '',
        className: []
      },
      formBox_3_arr: [],
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' }
          // { min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择活动类型', trigger: 'change' }
        ],
        goods_type: [
          { required: true, message: '请选择商品类型', trigger: 'change' }
        ],
        grade: [
          { required: true, message: '请选择所属年纪', trigger: 'change' }
        ],
        start_time: [
          { required: true, message: '请选择开始时间', trigger: 'change' }
        ],
        end_time: [
          { required: true, message: '请选择结束时间', trigger: 'change' }
        ],
        book_type: [
          { required: true, message: '请选择教材版本', trigger: 'change' }
        ],
        coins: [{ required: true, message: '请输入赠送金额', trigger: 'blur' }]
      }
    }
  },
  watch: {},
  created () {},
  activated () {
    this.getSelectData()
  },
  methods: {
    // 上传封面至oss请求
    async uploadImg (e) {
      let formData = new FormData()
      formData.append('file', e.file)
      let res = await ossUpload(formData, 'COURSE_COVER')
      if (res[0]) {
        return
      }
      this.ruleForm.cover_path = res[1].data.url
    },
    async uploadImg_poster_path (e) {
      let formData = new FormData()
      formData.append('file', e.file)
      let res = await ossUpload(formData, 'COURSE_COVER')
      if (res[0]) {
        return
      }
      this.ruleForm.poster_path = res[1].data.url
    },
    // 上传封面前验证
    beforeUploadImg (file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 5

      if (!isJPG) {
        this.$message.error('上传的图片只能是 JPG 或 PNG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传的图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    },
    setEndTime (e) {
      if (this.ruleForm.start_time > this.ruleForm.end_time) {
        this.ruleForm.end_time = ''
        this.$message({
          message: '结束时间不得早于开始时间',
          type: 'warning'
        })
      }
    },
    deleteBox (name, index) {
      this[name].splice(index, 1)
    },
    remoteMethod (query) {
      if (query !== '') {
        this.loading = true
        setTimeout(async () => {
          this.options = []
          let res = await getCourseList({
            'page.currPage': 1,
            'page.pageSize': 99999,
            'nice_course.name': query,
            'nice_course.status': 1
          })
          if (res[0]) {
            return
          }
          res[1].data.pageList.list.map(item => {
            this.options.push({ label: item.name, value: item.id })
          })
          this.loading = false
        }, 200)
      } else {
        this.options = []
      }
    },
    addCourse (form, e) {
      if (!this[form].name || this[form].className.length < 1) {
        this.$message({
          message: '请完善活动名称与课程姓名',
          type: 'warning'
        })
        return
      }
      let course = []
      this[form].className.map((item, index) => {
        course.push({
          course_id: item,
          course_Name: jquery('#select_' + e).find('.el-select__tags-text')[
            index
          ].textContent
        })
      })
      this['formBox_' + e + '_arr'].push({
        goods_name: this[form].name,
        course: course
      })
      this[form].name = ''
      this[form].className = ''
    },
    deleteCourse () {
      if (this.ruleForm.course_id.length > 1) {
        this.ruleForm.course_id.pop()
        this.ruleForm.course_time_id.pop()
      }
    },
    changeListTime () {
      this.ruleForm.end_time = ''
    },
    changeTerm (e) {
      this.gradeCopy = e
    },
    changeGrade (e, carate) {
      if (carate !== 'carate') {
        this.ruleForm.term = ''
      }
      if (e === null) {
        this.gradeLabel = '全部'
      } else {
        this.selectArr.grade.map(item => {
          if (item.value === e) {
            this.gradeLabel = item.label
          }
        })
      }
    },
    typeLabel (e) {
      this.ismultiple = false
      // console.log(e, this.selectArr.type)
      this.selectArr.type.map(item => {
        if (item.value === e && item.label === '专题特训课') {
          this.ismultiple = true
          // if (this.ruleForm.version) {
          //   this.ruleForm.versionArr = [].concat(this.ruleForm.version)
          // }
        }
      })
    },
    // 获取下拉菜单数据
    async getSelectData () {
      this.truleForm = {
        name: '',
        type: '',
        grade: '',
        start_time: '',
        end_time: '',
        coins: '',
        buy_radix: '',
        book_type: '',
        goods_type: ''
      }
      this.formBox_1 = {
        original_price: '',
        discount_type: 1,
        price: '',
        name: '',
        className: []
      }
      this.formBox_1_arr = []
      this.formBox_2 = {
        original_price: '',
        discount_type: 2,
        price: '',
        name: '',
        className: []
      }
      this.formBox_2_arr = []
      this.formBox_3 = {
        original_price: '',
        discount_type: 3,
        price: '',
        name: '',
        className: []
      }
      this.formBox_3_arr = []
      this.$refs.ruleForm.resetFields()
      let res = await getActivityResource({})
      if (res[0]) {
        return
      }
      let arr = res[1].data
      Object.keys(this.selectArr).forEach(item => {
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].fieldName === item) {
            this.selectArr[item] = arr[i].sourceData.child
          }
        }
      })
      this.selectArr = JSON.parse(
        JSON.stringify(this.selectArr)
          .split('display_value')
          .join('label')
          .split('child')
          .join('children')
          .split('t_id')
          .join('value')
      )
      // 根据id获取课程信息
      this.formBox_1.discount_type = this.selectArr.discount_type[0].value
      this.formBox_2.discount_type = this.selectArr.discount_type[1].value
      this.formBox_3.discount_type = this.selectArr.discount_type[2].value
      console.log()
      if (this.$route.query.id) {
        this.getActivityDetailsFn()
      }
    },
    // 根据id获取信息
    async getActivityDetailsFn () {
      let res = await getActivityDetails({ id: this.$route.query.id })
      if (res[0]) {
        return
      }
      let data = res[1].data[0]
      this.ruleForm = {
        name: data.name,
        type: data.type,
        grade: data.grade,
        start_time: data.start_time,
        end_time: data.end_time,
        coins: data.coins,
        buy_radix: data.buy_radix,
        book_type: data.book_type,
        goods_type: data.goods_type
      }
      let goodsForOne = data.goodsForOne
      let goodsForTwo = data.goodsForTwo
      let goodsForThree = data.goodsForThree
      if (goodsForOne.length > 0) {
        this.formBox_1.original_price = goodsForOne[0].original_price
        this.formBox_1.price = goodsForOne[0].price
        goodsForOne.map(item => {
          let course = []
          item.courseList.map(_item => {
            course.push({
              course_id: _item.course_id,
              course_Name: _item.course_name
            })
          })
          this.formBox_1_arr.push({ goods_name: item.name, course: course })
        })
      }
      if (goodsForTwo.length > 0) {
        this.formBox_2.original_price = goodsForTwo[0].original_price
        this.formBox_2.price = goodsForTwo[0].price
        goodsForTwo.map(item => {
          let course = []
          item.courseList.map(_item => {
            course.push({
              course_id: _item.course_id,
              course_Name: _item.course_name
            })
          })
          this.formBox_2_arr.push({ goods_name: item.name, course: course })
        })
      }
      if (goodsForThree.length > 0) {
        this.formBox_3.original_price = goodsForThree[0].original_price
        this.formBox_3.price = goodsForThree[0].price
        goodsForThree.map(item => {
          let course = []
          item.courseList.map(_item => {
            course.push({
              course_id: _item.course_id,
              course_Name: _item.course_name
            })
          })
          this.formBox_3_arr.push({ goods_name: item.name, course: course })
        })
      }
      console.log(goodsForOne, 'asdasdasdsadsads')
    },

    // 表单验证
    // 新增课程信息请求
    async addActivityFn () {
      let discount = []
      if (
        this.formBox_1.original_price &&
        this.formBox_1.price &&
        this.formBox_1_arr.length > 0
      ) {
        let goodsList = []
        this.formBox_1_arr.map(item => {
          let courseId = []
          item.course.map(item_ => {
            courseId.push(item_.course_id)
          })
          goodsList.push({
            goods_name: item.goods_name,
            course_id: courseId
          })
        })
        discount.push({
          discount_type: this.formBox_1.discount_type,
          price: this.formBox_1.price,
          original_price: this.formBox_1.original_price,
          goodsList: goodsList
        })
      }
      if (
        this.formBox_2.original_price &&
        this.formBox_2.price &&
        this.formBox_2_arr.length > 0
      ) {
        let goodsList = []
        this.formBox_2_arr.map(item => {
          let courseId = []
          item.course.map(item_ => {
            courseId.push(item_.course_id)
          })
          goodsList.push({
            goods_name: item.goods_name,
            course_id: courseId
          })
        })
        discount.push({
          discount_type: this.formBox_2.discount_type,
          price: this.formBox_2.price,
          original_price: this.formBox_2.original_price,
          goodsList: goodsList
        })
      }
      if (
        this.formBox_3.original_price &&
        this.formBox_3.price &&
        this.formBox_3_arr.length > 0
      ) {
        let goodsList = []
        this.formBox_3_arr.map(item => {
          let courseId = []
          item.course.map(item_ => {
            courseId.push(item_.course_id)
          })
          goodsList.push({
            goods_name: item.goods_name,
            course_id: courseId
          })
        })
        discount.push({
          discount_type: this.formBox_3.discount_type,
          price: this.formBox_3.price,
          original_price: this.formBox_3.original_price,
          goodsList: goodsList
        })
      }
      let res = await addActivity({
        name: this.ruleForm.name,
        type: this.ruleForm.type,
        grade: this.ruleForm.grade,
        start_time: this.ruleForm.start_time,
        end_time: this.ruleForm.end_time,
        coins: this.ruleForm.coins,
        buy_radix: this.ruleForm.buy_radix,
        book_type: this.ruleForm.book_type,
        discount: discount,
        cover_path: this.ruleForm.cover_path,
        poster_path: this.ruleForm.poster_path,
        goods_type: this.ruleForm.goods_type
      })
      if (res[0]) {
        return
      }
      this.$message({
        message: '保存活动成功',
        type: 'success'
      })
      setTimeout(() => {
        this.$router.push({ name: 'activity' })
      }, 800)
    },
    // 修改课程信息请求
    async updateCoures () {
      let version
      this.ismultiple
        ? (version = this.ruleForm.versionArr.join(','))
        : (version = this.ruleForm.version)
      let res = await updateCourse([
        {
          table_name: 'nice_course',
          update: [
            {
              name: this.ruleForm.name, // --
              type: this.ruleForm.type, // -- 分类
              grade: this.ruleForm.grade, // -- 年级
              subject: this.ruleForm.subject, // -- 科目
              version: version, // -- 版本
              // time: 8, // --
              term: this.ruleForm.term,
              cover_path: this.ruleForm.cover_path,
              introduction_video: this.ruleForm.introduction_video,
              poster_path: this.ruleForm.poster_path,
              level: this.ruleForm.level, // -- 课程难度
              description: this.ruleForm.description, // --简介
              status: this.ruleForm.status, // --  0 保存 1 保存并发布
              has_teaching_materials: this.ruleForm.has_teaching_materials,
              goods_type: this.ruleForm.goods_type
            }
          ],
          where: [
            {
              id: this.$route.query.id
            }
          ]
        }
      ])
      if (res[0]) {
        return
      }
      this.$router.push({ name: 'class-list' })
      console.log(res[1])
    },

    submitForm (formName, e) {
      this.ruleForm.status = e
      this.$refs[formName].validate(valid => {
        if (valid) {
          //   console.log(1)
          //   // 新增课程
          //   if (!this.$route.query.id) {
          this.addActivityFn()
          // } else {
          //   // 修改课程
          //   this.updateCoures()
          // }
        } else {
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    randomString () {
      let len = 7
      let $chars =
        'ABCDEFGHJKMNPQRSTWXYZ0123456789' /** **默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
      let maxPos = $chars.length
      let pwd = ''
      for (let i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos))
      }
      return pwd
    }
  }
}
</script>
<style scoped>
h2 {
}
.u-form-box {
  width: 670px;
  padding-bottom: 50px;
}
.u-form-item-rate {
  padding-top: 9px;
}
.cascader {
  width: 100%;
}
.u-title-h2 {
  padding-left: 60px;
  margin-bottom: 40px;
}
.optionShow {
  display: none;
}
.u-info-text {
  font-size: 12px;
}
.u-title-h3 {
  padding-left: 60px;
}
hr {
  margin-bottom: 20px;
}
.u-list-box {
  display: flex;
  justify-content: space-between;
  border: 1px dashed #c3c3c3;
  padding: 15px 60px;
  border-radius: 12px;
  align-items: center;
  display: flex;
  margin-bottom: 25px;
}
.u-list-name {
  margin-right: 80px;
}
.u-save {
  margin-top: 20px;
  margin-left: 60px;
  margin-bottom: 50px;
}
.u-mar-right-20 {
  margin-right: 10px;
}
.u-time-box {
  width: 400px;
}
</style>
